<%@ page import="com.zwy.Shopping.model.Product" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/bootstrap.bundle.js"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.validate.min.js"></script>
    <script src="js/messages_zh.js"></script>


    <% Product p = (Product) request.getSession().getAttribute("modify_product");%>
    <meta charset="UTF-8">
    <title>立即购买</title>
    <style>
        .error{
            color:red;
        }
    </style>
</head>
<body>



<div class="container-fluid mt-3 d-flex">
    <div class="card w-25 m-auto d-flex">

        <div class="card-title m-auto d-flex">修改商品信息界面</div>
        <div class="card-img-top m-auto d-flex"><img class="img-thumbnail m-auto" src="img/<%=p.getImage()%>"></div>
        <div class="card-footer m-auto d-flex">
            <form class="form-control m-auto" id="modifyProductForm" action="modify_product" method="post" enctype="multipart/form-data">

            <div>
                <label class="d-flex">商品名:</label>
                <input type="text" value="<%=p.getName()%>" id="productName" name="productName">
            </div>
            <div>
                <label class="d-flex">市场价格:</label>
                <input type="text" value="<%=p.getMarketPrice()%>" id="productMarketPrice" name="productMarketPrice">
            </div>
            <div>
                <label class="d-flex">价格:</label>
                <input type="text" value="<%=p.getPrice()%>" id="productPrice" name="productPrice">
            </div>
            <div>
                <label class="d-flex">图片:</label>
                <input type="file" value="<%=p.getImage()%>" id="productImage" name="productImage">
            </div>
            <div>
                <label class="d-flex">库存:</label>
                <input type="text" value="<%=p.getStock()%>" id="productStock" name="productStock">
            </div>

            <%request.getSession().setAttribute("modify_productId",p.getId());%>
                <div class="mt-3">
                    <button class="btn btn-primary" type="submit" >立刻修改</button>
                    <a class="btn btn-secondary" href="admin_index.jsp">返回首页</a>
                </div>

            </form>
        </div>
    </div>
</div>
</body>
</html>
<script>

    $().ready(function () {

        // 初始化验证
        $("#modifyProductForm").validate({
            rules: {
                productName:{required:true},
                productMarketPrice:{required:true},
                productPrice:{required:true},
                productImage:{required:true},
                productStock:{required:true}
            }
        });
    });
</script>
